package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.SetPayModeBean;
import com.ymatou.iapi.godmch.parameter.addProviderBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.SetPayModeCall;
import com.ymatou.iapi.godmch.service.addProviderCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
/**
*设置商户支付通道Test
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
public class Ts_SetPayMode{
	private static SetPayModeBean setpaymodeBean;
	private static SetPayModeCall setpaymodeCall;
	private static mch_infoWapper mchInfoWapper = new mch_infoWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商户支付通道(与 setShareType 合并一个接口,此接口作废)");
	}

	@Before
	public void caseUp() {
		setpaymodeBean=new SetPayModeBean();
		setpaymodeCall=new SetPayModeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setpaymodeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_001() {
		Logger.start(true, "切换到盛付通，渠道-没有代理-成功");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			// 获取客服信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		    Logger.verifyEquals(3, mchInfo.getPayMode(), "验证paymode=3");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_002() {
		Logger.start(true, "切换到盛付通，渠道切盛付通-有代理-失败");
		try {
//			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
//			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			//创建一个渠道商-代理
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(mchId);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			
		   Logger.verifyEquals(5000,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
		   Logger.verifyEquals(true,setpaymodeCall.getJsonObject().get("msg").toString().contains("有下级代理的渠道商禁止切换支付通道"),"验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_003() {
		Logger.start(true, "切换到盛付通，代理-切支付通道-失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(mchId);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			setpaymodeBean.setMchId(createmchList.get(0).getMchId());
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(5000,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			Logger.verifyEquals(true,setpaymodeCall.getJsonObject().get("msg").toString().contains("仅单一渠道商身份的商户才可切换支付通道"),"验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_004() {
		Logger.start(true, "切换到盛付通，服务商-失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			addProviderBean addProviderBean = GodmchManageCallService.InitAddProviderBean();
			addProviderCall addProviderCall=GodmchManageCallService.InitAddProviderCall(addProviderBean);
			
			setpaymodeBean.setMchId(addProviderBean.getProviderId());
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(5000,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			Logger.verifyEquals(true,setpaymodeCall.getJsonObject().get("msg").toString().contains("服务商身份禁止切换支付通道"),"验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_005() {
		Logger.start(true, "切换到盛付通，服务商-有商户-失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			addProviderBean addProviderBean = GodmchManageCallService.InitAddProviderBean();
			addProviderCall addProviderCall=GodmchManageCallService.InitAddProviderCall(addProviderBean);
			
			GodmchManageCallService.InitAddServiceRelation(addProviderBean.getProviderId(),mchId,1);

			setpaymodeBean.setMchId(addProviderBean.getProviderId());
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(5000,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			Logger.verifyEquals(true,setpaymodeCall.getJsonObject().get("msg").toString().contains("服务商身份禁止切换支付通道"),"验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_005_1() {
		Logger.start(true, "切换到盛付通，服务商-有商户-商户切换盛付通-失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			addProviderBean addProviderBean = GodmchManageCallService.InitAddProviderBean();
			addProviderCall addProviderCall=GodmchManageCallService.InitAddProviderCall(addProviderBean);
			
			GodmchManageCallService.InitAddServiceRelation(addProviderBean.getProviderId(),mchId,1);

			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(5000,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			Logger.verifyEquals(true,setpaymodeCall.getJsonObject().get("msg").toString().contains("与服务商有绑定关系禁止切换支付通道"),"验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_006() {
		Logger.start(true, "切换到盛付通，独立小程序-失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.initsetShareType(mchId,3);
	
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			// 获取客服信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		    Logger.verifyEquals(3, mchInfo.getPayMode(), "验证paymode=3");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_007() {
		Logger.start(true, "切换到盛付通，独立H5-失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.initsetShareType(mchId,4);
	
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();

			// 获取客服信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		    Logger.verifyEquals(3, mchInfo.getPayMode(), "验证paymode=3");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_008() {
		Logger.start(true, "切换到盛付通，独立商户-失败");
		try {
			
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			
			setpaymodeBean.setMchId(createIndepMchCall.getmchId());
			setpaymodeBean.setPayMode(3);//
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();

			// 获取客服信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", createIndepMchCall.getmchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		    Logger.verifyEquals(3, mchInfo.getPayMode(), "验证paymode=3");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_009() {
		Logger.start(true, "切换到盛付通，商户id不存在");
		try {
			setpaymodeBean.setMchId(111);
			setpaymodeBean.setPayMode(3);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(5004,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			Logger.verifyEquals(true,setpaymodeCall.getJsonObject().get("msg").toString().contains("商户不存在"),"验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_010() {
		Logger.start(true, "切换到支付宝支付通道-1：飞界国际，渠道-没有代理-成功");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到商品id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setpaymodeBean.setMchId(mchId);
			setpaymodeBean.setPayMode(3);
			setpaymodeBean.setAliPayMode(1);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			// 获取客服信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		    Logger.verifyEquals(3, mchInfo.getPayMode(), "验证paymode=3");
		    Logger.verifyEquals(1, mchInfo.getAliPayMode(), "验证AliPayMode=1");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_011() {
		//新增支付宝支付通道 20191224
		Logger.start(true, "切换到支付宝支付通道-1：飞界国际，设置有代理的渠道-渠道设置成功，代理不变-成功");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			GodmchManageCallService.SetVip(ccbean.getMchId());
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			
			setpaymodeBean.setMchId(ccbean.getMchId());
			setpaymodeBean.setPayMode(2);
			setpaymodeBean.setAliPayMode(1);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			// 获取渠道信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		    Logger.verifyEquals(2, mchInfo.getPayMode(), "验证渠道paymode=2");
		    Logger.verifyEquals(1, mchInfo.getAliPayMode(), "验证渠道AliPayMode=1");
		    //获取代理
			Map<String, Object> map2 = new HashMap();
			map2.put("mchId",agentid);
			mch_info mchInfo2 = mchInfoWapper.selectby(map2).get(0);
		    Logger.verifyEquals(2, mchInfo2.getPayMode(), "验证代理paymode=2");
		    Logger.verifyEquals(0, mchInfo2.getAliPayMode(), "验证代理AliPayMode=0");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetPayMode_012() {
		Logger.start(true, "切换到支付宝支付通道-1：飞界国际，设置代理-代理设置成功，渠道不变-成功");
		try {
			//新增支付宝支付通道 20191224
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			GodmchManageCallService.SetVip(ccbean.getMchId());
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			
			setpaymodeBean.setMchId(agentid);
			setpaymodeBean.setPayMode(2);
			setpaymodeBean.setAliPayMode(1);
			setpaymodeCall.setData(setpaymodeBean);
			setpaymodeCall.callService();
			Logger.verifyEquals(200,setpaymodeCall.getJsonObject().get("status").getAsInt(),"验证code");
			// 获取渠道信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", ccbean.getMchId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		    Logger.verifyEquals(2, mchInfo.getPayMode(), "验证渠道paymode=2");
		    Logger.verifyEquals(0, mchInfo.getAliPayMode(), "验证渠道AliPayMode=0");
		    //获取代理
			Map<String, Object> map2 = new HashMap();
			map2.put("mchId",agentid);
			mch_info mchInfo2 = mchInfoWapper.selectby(map2).get(0);
		    Logger.verifyEquals(2, mchInfo2.getPayMode(), "验证代理paymode=2");
		    Logger.verifyEquals(1, mchInfo2.getAliPayMode(), "验证代理AliPayMode=1");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}